﻿Imports System.Net.Mail
Imports NetSmtpClient = System.Net.Mail.SmtpClient
Imports Equipment.Core

''' <summary>
''' An realization of <see cref="SmtpClient"/> that uses <see cref="ISmtpClient"/> for sending mails
''' </summary>
Public Class StandardSmtpClient
    Implements ISmtpClient
    Private ReadOnly _client As NetSmtpClient

    '''<summary>
    ''' Initializes a new instance of the StandardSmtpClient class that sends e-mail by using
    ''' standard <see cref="SmtpClient"/> class.
    '''</summary>
    '''<param name="host">A String that contains the name or IP address of the host
    '''computer used for SMTP transactions</param>
    ''' <exception cref="ArgumentException">Host name is null or empty</exception>
    Public Sub New(ByVal host As String)
        If String.IsNullOrEmpty(host) Then
            Throw New ArgumentException("Host name is null or empty")
        End If

        _client = New NetSmtpClient(host)
        _client.UseDefaultCredentials = Sys.SMTPSettings.Network.DefaultCredentials
        _client.Port = Sys.SMTPSettings.Network.Port
        _client.Credentials = New System.Net.NetworkCredential(Sys.SMTPSettings.Network.UserName, Sys.SMTPSettings.Network.Password)
    End Sub
    ''' <summary>
    ''' Sends the <paramref name="message"/> to recipients
    ''' </summary>
    ''' <param name="message">A mail message to send</param>
    Public Sub Send(ByVal message As MailMessage) Implements ISmtpClient.Send
        _client.Send(message)
    End Sub
End Class
